﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project_V1
{
    public partial class TextBoxControl : UserControl
    {
        public TextBoxControl()
        {
            InitializeComponent();
            Timer mytimer = new Timer();
            mytimer.Interval = 1000;
            mytimer.Tick += Mytimer_Tick;
            mytimer.Enabled = true;
        }

        //由控件Tag写入的变量名循环读取CurrentValue变量名对应的值
        private void Mytimer_Tick(object sender, EventArgs e)
        {
            if (this.Tag != null)
            {
                //if (CommonMethods.CurrentValue != null && CommonMethods.CurrentValue.ContainsKey(this.Tag.ToString()))
                //{
                //    this.ActualValue = CommonMethods.CurrentValue[this.Tag.ToString()];
                //}
            }
        }

        #region 自定义控件的属性ActualValue,Unit

        //数值
        private string actualValue="0.0";
        public string ActualValue
        {
            get { return actualValue; }
            set
            {
                actualValue = value;
                this.lbl_data.Text = actualValue;
            }
        }

        /// <summary>
        /// 单位
        /// </summary>
        private string unit="rpm";
        public string Unit
        {
            get { return unit; }
            set
            {
                unit = value;
                this.lbl_unit.Text = unit;
            }
        }
        #endregion

        //创建委托, 控件自定义事件UserControlClick,用来写入数值
        public delegate void BtnClickDelagate(object sender, EventArgs e);
        //自定义事件
        public event BtnClickDelagate UserControlClick;

        //标签数值部分lbl_data的双击事件,把按钮自身作为参数传递
        private void lbl_data_DoubleClick(object sender, EventArgs e)
        {
            if (UserControlClick != null)
            {
                UserControlClick(this, new EventArgs());
            }
        }

        private void lbl_unit_Click(object sender, EventArgs e)
        {

        }
    }
}
